package utils;

import jdk.swing.interop.SwingInterOpUtils;

import java.io.*;
import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.*;

public class ScheduledUtils {

	public static void  delay(Runnable runnable, long delay){
		Timer timer = new Timer();
		timer.schedule(new TimerTask() {
			@Override
			public void run() {
				runnable.run();
			}
		}, delay);
	}
	static int i =0;

	private static final ThreadFactory nameThreadFactory= new ThreadFactory() {
		int i=0;
		@Override
		public Thread newThread(Runnable r) {
			return Thread.ofVirtual().name("thread-"+i++).unstarted(r);
		}
	};
	public static void main(String[] args) throws InterruptedException {

		ThreadPoolExecutor platform = new ThreadPoolExecutor(1,
				1,
				60,
				TimeUnit.SECONDS,
				new ArrayBlockingQueue<>(100),
				Thread.ofPlatform().factory(),
				new ThreadPoolExecutor.CallerRunsPolicy());


		ThreadPoolExecutor virtual = new ThreadPoolExecutor(1,
				1,
				60,
				TimeUnit.SECONDS,
				new ArrayBlockingQueue<>(100),
				Thread.ofVirtual().factory(),
				new ThreadPoolExecutor.CallerRunsPolicy());

		Runnable runnable = () -> {
			System.out.println("after");
			try {
				Thread.sleep(1000);
			} catch (InterruptedException e) {
				throw new RuntimeException(e);
			}
			System.out.println("before");

		};


		while (true);


	}

}
